#include "htmltextdelegate.h"
#include <QTextDocument>
#include <QPainter>

HtmlTextDelegate::HtmlTextDelegate(QObject *parent)
	: QItemDelegate(parent)
{

}

HtmlTextDelegate::~HtmlTextDelegate()
{

}

void HtmlTextDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const{
	painter->save();

	QTextDocument doc;
	QVariant value = index.data(Qt::DisplayRole);
	if(value.isValid() && !value.isNull()){
		QString text;
		text.append(value.toString());

		doc.setHtml(text);
		painter->translate(option.rect.topLeft());
		doc.drawContents(painter);
		painter->restore();
	}
}